package yu.liu.personal.app.myapplication.components.parts;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import yu.liu.personal.app.myapplication.R;
import yu.liu.personal.app.myapplication.components.ViewCollection;

/**
 * Created by yu.liu on 2016/9/28.
 */

public class FunctionBarAvgListPage extends ViewCollection {

    @BindView(R.id.btnFilterFunc)
    View btnFilterFunc;
    @BindView(R.id.editSearchFuncs)
    EditText editSearchFuncs;
    @BindView(R.id.btnSearchFunc)
    View btnSearchFunc;
    @BindView(R.id.btnCompareFunc)
    TextView btnCompareFunc;
    @BindView(R.id.btnCompareRunFunc)
    TextView btnCompareRunFunc;

    private Handler functionHandler;

    public static final int FUNC_FILTER = 0;
    public static final int FUNC_SEARCH = 1;
    public static final int FUNC_COMPARE = 2;
    public static final int FUNC_COMPARE_RUN = 3;

    public FunctionBarAvgListPage(Context context) {
        super(context);
    }

    public void setFunctionHandler(Handler functionHandler) {
        this.functionHandler = functionHandler;
    }

    @Override
    protected void loadViews() {
        ButterKnife.bind(this, contentView);
    }

    @Override
    public void updateViews() {

    }

    public void setCompareRunBtn(boolean available) {
        if(available) {
            btnCompareFunc.setText("对比");
            btnCompareRunFunc.setTextColor(Color.parseColor("#888888"));
        } else {
            btnCompareFunc.setText("取消");
            btnCompareRunFunc.setTextColor(Color.parseColor("#3366ff"));
        }
    }

    @OnClick(R.id.btnFilterFunc)
    public void filterClick() {
        if(functionHandler != null) {
            functionHandler.sendEmptyMessage(FUNC_FILTER);
        }
    }

    @OnClick(R.id.btnSearchFunc)
    public void searchClick() {
        if(functionHandler != null) {
            Message msg = Message.obtain();
            msg.what = FUNC_SEARCH;
            msg.obj = editSearchFuncs.getText().toString();
            functionHandler.sendMessage(msg);
        }
    }

    @OnClick(R.id.btnCompareFunc)
    public void compareClick() {
        if(functionHandler != null) {
            functionHandler.sendEmptyMessage(FUNC_COMPARE);
        }
    }

    @OnClick(R.id.btnCompareRunFunc)
    public void compareRunClick() {
        if(functionHandler != null) {
            functionHandler.sendEmptyMessage(FUNC_COMPARE_RUN);
        }
    }
}
